﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using FrienDev.BusinessRules;
using FrienDev.Data;
using System.Collections.Generic;

public partial class Controls_Users_FriendsList : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ApiHelper.Instance.IsFriendsPage())
        {
            if (!ApiHelper.Instance.IsVisible(UserRules.Instance.GetCurrentUserId(), ApiHelper.Instance.GetRequestUserId(), "DefaultPage") || !ApiHelper.Instance.IsVisible(UserRules.Instance.GetCurrentUserId(), ApiHelper.Instance.GetRequestUserId(), "FriendsList"))
            {
                allFriendsLink.Visible = false;
            }
        }
        List<User> myData;
        if (ApiHelper.Instance.IsFriendsPage())
        {
            title.Text = "他的好友";
            IEnumerable<User> tempData = FriendRules.Instance.GetFriendsListByUserId(ApiHelper.Instance.GetRequestUserId(), 15);
            myData = tempData.ToList<User>();
            allFriendsLink.NavigateUrl = "/home/friends.aspx?uid="+ApiHelper.Instance.GetRequestUserId();
        }
        else
        {
            title.Text = "我的好友";
            IEnumerable<User> tempData = FriendRules.Instance.GetFriendsListByUserId(UserRules.Instance.GetCurrentUserId(), 15);
            myData = tempData.ToList<User>();
            allFriendsLink.NavigateUrl = "/home/friends.aspx";
        }
        DataList1.DataSource = myData;
        DataList1.DataBind();
    }
    protected void DataList1_Load(object sender, EventArgs e)
    {
        
    }
    protected void HY_DataBinding(object sender, EventArgs e)
    {
        HyperLink hy = sender as HyperLink;
        hy.NavigateUrl = ApiHelper.Instance.GetUserHomepageLink(hy.NavigateUrl);
    }

    protected void Img_DataBinding(object seder, EventArgs e)
    {
        Image img = seder as Image;
        img.ImageUrl = ApiHelper.Instance.GetUserLogoUrl(img.ImageUrl);
    }
}
